package com.cj.peiwan.server.other;

import java.util.HashMap;

import com.cloopen.rest.sdk.CCPRestSDK;
import com.google.gson.Gson;

public class RongLian {
    private static final String apiKey = "8a48b5514cc6710b014ccb44dd7f02e6";
    private static final String apiSecret = "71a5a480fb664c5084125fbd33d63829";
    public static final int TEMPLATE_ID = 27779;
    private static final String IP = "app.cloopen.com";
    private static final String PORT = "8883";
    private static final String appId = "aaf98f894ebe0e7e014ec3fd950a0781";

    public static RonglianResponse sendCodeMessage(String code, String to) {
        CCPRestSDK restAPI = new CCPRestSDK();
        restAPI.init(IP, PORT);// 初始化服务器地址和端口，格式如下，服务器地址不需要写https://
        restAPI.setAccount(apiKey, apiSecret);// 初始化主帐号名称和主帐号令牌
        restAPI.setAppId(appId);// 初始化应用ID
        HashMap<String, Object> map = restAPI.sendTemplateSMS(to, TEMPLATE_ID
                + "", new String[]{code});
        Gson gson = new Gson();
        String json = gson.toJson(map);
        RonglianResponse ronglianResponse = gson.fromJson(json,
                RonglianResponse.class);
        return ronglianResponse;
    }

    public static RonglianResponse sendOrderMessage(String nickname, String to) {
        CCPRestSDK restAPI = new CCPRestSDK();
        restAPI.init(IP, PORT);// 初始化服务器地址和端口，格式如下，服务器地址不需要写https://
        restAPI.setAccount(apiKey, apiSecret);// 初始化主帐号名称和主帐号令牌
        restAPI.setAppId(appId);// 初始化应用ID
        HashMap<String, Object> map = restAPI.sendTemplateSMS(to, 47233
                + "", new String[]{nickname});
        Gson gson = new Gson();
        String json = gson.toJson(map);
        RonglianResponse ronglianResponse = gson.fromJson(json,
                RonglianResponse.class);
        return ronglianResponse;
    }

    public static void main(String[] args) throws Exception {
        RonglianResponse response = sendOrderMessage("宅男的福音",
                "18874143580");
        System.out.println(response.getStatusCode());
        System.out.println(response.getStatusMsg());
    }
}
